package cn.edu.hznu.web.crawl;

import java.io.IOException;

import org.apache.http.ParseException;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;

public class CrawlWithCookie {
	
	final static String ROOTURL = "http://douban.com/";
	
	
	public void crawl() {
		BasicCookieStore cookieStore = new BasicCookieStore();
		cookieStore.addCookie(new BasicClientCookie("bid", "Sj3g9efI2HA"));
		cookieStore.addCookie(new BasicClientCookie("ps", "y"));
		cookieStore.addCookie(new BasicClientCookie("ue", "791914240@qq.com"));
		cookieStore.addCookie(new BasicClientCookie("dbcl2", "70589717:ErKcnG5HWeE"));
		cookieStore.addCookie(new BasicClientCookie("ck", "6K7_"));
		cookieStore.addCookie(new BasicClientCookie("_pk_id.100001.8cb4", "18180052996f7f61.1446615038.2.1446617913.1446615152."));
		cookieStore.addCookie(new BasicClientCookie("_pk_ses.100001.8cb4", "*"));
		cookieStore.addCookie(new BasicClientCookie("push_noty_num", "0"));
		cookieStore.addCookie(new BasicClientCookie("push_doumail_num", "6"));
		cookieStore.addCookie(new BasicClientCookie("__utma", "30149280.1982246938.1446615040.1446615040.1446615040.1"));
		cookieStore.addCookie(new BasicClientCookie("__utmb", "30149280.13.10.1446615040"));
		cookieStore.addCookie(new BasicClientCookie("__utmc", "30149280"));
		cookieStore.addCookie(new BasicClientCookie("__utmz", "30149280.1446615040.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"));
		cookieStore.addCookie(new BasicClientCookie("__utmv", "30149280.7058"));
		
		try {
			String responseBody = DownloadContent
					.getStrContentFormUrlWithCookie(ROOTURL, cookieStore, "utf-8");
			
//			String strCookie = "bid=\"Sj3g9efI2HA\"; "
//								+ "ps=y; "
//								+ "ue=\"791914240@qq.com\"; "
//								+ "dbcl2=\"70589717:ErKcnG5HWeE\"; "
//								+ "ck=\"6K7_\"; "
//								+ "_pk_id.100001.8cb4=18180052996f7f61.1446615038.2.1446618609.1446615152.; "
//								+ "push_noty_num=0; "
//								+ "push_doumail_num=6; "
//								+ "__utma=30149280.1982246938.1446615040.1446615040.1446615040.1; "
//								+ "__utmb=30149280.15.10.1446615040; "
//								+ "__utmc=30149280; "
//								+ "__utmz=30149280.1446615040.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); "
//								+ "__utmv=30149280.7058; "
//								+ "_pk_ses.100001.8cb4=*";
//			String responseBody = DownloadContent
//					.getStrContentFormUrlWithCookie(ROOTURL, strCookie, "utf-8");
			
			System.out.println(responseBody.substring(0, 10000));
			
		} catch (ParseException | IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
}
